package thread2;

public class Worker extends Thread {
	public Worker(String n) {
		super(n);
	}

	@Override
	public void run() {
		while (true) {
			System.out.println(super.getName() + "工作了一会");
			try {
				super.sleep(500);// 毫秒
				System.out.println("睡醒了，开始继续干活");
			} catch (InterruptedException e) {
				// TODO 自动生成的 catch 块

				e.printStackTrace();
				System.out.println("被喊醒，继续干活");
			}
		}
	}

	public static void main(String[] args) {
		Thread.currentThread().setName("黄世仁");
		Worker w = new Worker("杨白劳");
		w.start();
		while (true) {
			try {
				Thread.sleep(1200);
				System.out.println(Thread.currentThread().getName()
						+ "睡醒了，喊工人干活");
				w.interrupt();
			} catch (InterruptedException e) {
				// TODO 自动生成的 catch 块
				e.printStackTrace();
			}

		}
	}
}
